<template>
  <div class="login">
    <div class="container">
      <a href="/#/index">
        <img src="/imgs/login-logo.png" alt="">
      </a>
    </div>
    <div class="wrapper">
      <div class="container">
        <div class="login-form">
          <h3>
            <span class="checked">帐号登录</span>
            <span class="sep-line">|</span>
            <span>扫码登录</span>
          </h3>
          <div class="input">
            <input type="text" placeholder="请输入帐号" v-model="username">
          </div>
          <div class="input">
            <input type="password" placeholder="请输入密码" v-model="password" @keyup.enter="login">
          </div>
          <div class="btn-box">
            <button class="btn" @click="login" @keyup.enter.native="login">登录</button>
          </div>
          <div class="tips">
            <div class="sms" @click="register">手机短信登录/注册</div>
            <div class="reg">立即注册<span>|</span>忘记密码？</div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="footer-link">
        <a href="#">吴轶琛博客</a><span>|</span>
        <a href="#">Vue模仿小米商城</a><span>|</span>
        <a href="#">Vue后台模板</a><span>|</span>
        <a href="#">其他</a>
      </div>
      <p class="copyright">Copyright ©2019 mi.futurefe.com All Rights Reserved.</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data () {
    return {
      username: '',
      password: '',
      userId: ''
    }
  },
  methods: {
    login() {
      let { username, password } = this
      this.axios.post('/user/login', {
        username,
        password
      }).then((res) => {
        this.$cookie.set('userId', res.id, { expires: 'Session' })
        this.$store.dispatch('saveUserName', res.username)
        this.$router.push('/index')
        // query
        // this.$router.push({
        //  path: '/index'   // 注意需要写路径 这种方式会显示到地址栏上
        //  query: {
        //    from: 'login'
        //  }
        // })

        // params
        // this.$router.push({
        //  path: 'index'   // 注意需要写name 也就是rooter里面的对应name 这种方式不会显示到地址栏上
        //  params: {
        //    from: 'login'
        //  }
        // })
      })
    },
    register() {

    }
  }
}
</script>

<style scoped lang="scss">
  @import "./../assets/scss/config";
  @import "./../assets/scss/btn";

  .login {
    & > .container {
      height: 113px;

      img {
        width: auto;
      }
    }

    .wrapper {

      background: url('/imgs/login-bg.jpg') no-repeat center;

      .container {
        position: relative;
        height: 576px;

        .login-form {
          height: 510px;
          background-color: #fff;
          position: absolute;
          bottom: 29px;
          width: 410px;
          right: 0;
          box-sizing: border-box;
          padding: 0 30px;

          h3 {
            line-height: 23px;
            font-size: 24px;
            text-align: center;
            margin: 40px auto 49px;

            .sep-line {
              margin: 0 30px;
            }

            .checked {
              color: $colorA;
            }

            span {
              &:hover {
                color: $colorA;
                cursor: pointer;
              }
            }
          }

          .input {
            display: inline-block;
            width: 348px;
            height: 50px;
            border: 1px solid #e5e5e5;
            margin-bottom: 20px;

            input {
              box-sizing: border-box;
              width: 100%;
              height: 100%;
              border: none;
              padding: 18px;
            }
          }

          .btn {
            width: 100%;
            line-height: 50px;
            margin-top: 10px;
            height: 50px;
            font-size: 16px;
          }
          .tips {
            margin-top: 14px;
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            cursor: pointer;
            .sms {
              color: $colorA;
            }
            .reg{
              color: $colorD;
              span{
                margin: 0 6px;
              }
            }
          }
        }
      }
    }
    .footer{
      height:100px;
      padding-top:60px;
      color:#999999;
      font-size:16px;
      text-align:center;
      .footer-link{
        a{
          color:#999999;
          display:inline-block;
        }
        span{
          margin:0 10px;
        }
      }
      .copyright{
        margin-top:13px;
      }
    }
  }

</style>
